package com.winshare.saleAssistant.controller;

import com.winshare.saleAssistant.domain.dto.req.*;
import com.winshare.saleAssistant.service.RoleService;
import com.winshare.saleAssistant.util.LogicResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys/role")
@CrossOrigin
@Api(value = "角色管理", description = "角色管理")
public class RoleController {

    private final RoleService roleService;

    public RoleController(RoleService roleService) {
        this.roleService = roleService;
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增角色接口",notes = "新增角色接口")
    public LogicResponse save(@RequestBody @Validated RoleCreateDTO roleCreateDTO) {
        roleService.save(roleCreateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改角色接口",notes = "修改角色接口")
    public LogicResponse update(@RequestBody @Validated RoleUpdateDTO roleUpdateDTO) {
        roleService.update(roleUpdateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除角色接口",notes = "删除角色接口")
    public LogicResponse delete(@RequestBody @Validated RoleDeleteDTO roleDeleteDTO) {
        roleService.delete(roleDeleteDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/list")
    @ResponseBody
    @ApiOperation(value = "查询角色列表接口",notes = "查询角色列表接口")
    public LogicResponse queryRolePage(@RequestBody @Validated RoleQueryDTO roleQueryDTO) {
        return LogicResponse.success(roleService.getRoleList(roleQueryDTO));
    }

    @PostMapping("/detail")
    @ApiOperation(value = "获取单个角色")
    public LogicResponse getRole(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        return LogicResponse.success(roleService.getRoleDetail(baseIdDTO));
    }

    @PostMapping("/set/person")
    @ApiOperation(value = "角色菜单处设置人员接口",notes = "角色菜单处设置人员接口")
    public LogicResponse setPersonList(@RequestBody @Validated RoleSettingPeronDTO roleSettingPeronDTO) {
        roleService.setPersonList(roleSettingPeronDTO);
        return LogicResponse.success("success");
    }
}
